<%
# this page serves two purposes: for new or unregistered users, we display a
# little information about what flawmill is.  to registered users, we display a
# digest of flawmill activity: new assignments, new issues, their projects,
# their issues.
@owned_issues ||=[]
@recent_issues ||= []
-%>

<% if @current_user.nil? or (@time_delay < @current_user.created_at) -%>
  <h1>Welcome to FlawMill!</h1>

  <p>
    FlawMill is an enterprise issue tracker. It aims to provide a simple, powerful
    interface that maximizes your daily productivity. Feel free to take a look around at 
    <%= link_to 'recent projects', projects_url %>, and visit our 
    <%= link_to 'About', :action => 'about' %> or <%= link_to 'FAQ', :action => 'faq' %> 
    pages for more information.
  </p>
<% end -%>

<% if @current_user -%>
  <h1>Home</h1>
  <div class="float_container">
    <div class="floater" id="project_list_actions">
      <h2>Actions</h2>
      <ul>
        <!-- <li><%= link_to 'Search', "#" %></li> -->
        <li><%= link_to 'Browse Projects', projects_url %></li>
        <li><%= link_to 'Create a New Project', new_project_url %></li>
      </ul>
    </div>

    <div class="floater">
      <h2>Projects</h2>
      <p>
      <% @projects.each do |project| -%>
        <% div_for( project, :class => 'project_summary' ) do -%>
          <span class="name"><%= link_to h(project.name), project_url(project.name) %></span><br />
          <span class="issues">
            <%= link_to value( project.issues.open.size.to_s ) + ' open',
                        issues_path( project.name ) %>,
            <%= link_to value( (project.issues.size- project.issues.open.size).to_s ) + ' closed',
                        :controller => :issues, :project_id => project.name, :action => :closed %>
          </span>
          <span class="links">
            <ul>
              <li><%= link_to 'Submit an Issue', new_issue_path( project.name ) %></li><br />
              <li><%= link_to 'Project Forum', "#" %></li>
            </ul>
          </span>
        <% end -%>
      <% end -%>
      </p>
    </div>
  </div>

  <div class="issue_summaries" id="recent">
    <h3>Recently Updated</h3>
    <% @recent_issues.reverse.each do |issue| -%>
      <%= render :partial => 'shared/issue_summary', :locals => { :issue => issue } %>
    <% end -%>
  </div>

  <div class="issue_summaries" id="new">
    <h3>New</h3>
    <% @owned_issues.reverse.each do |issue| -%>
      <%= render :partial => 'shared/issue_summary', :locals => { :issue => issue } %>
    <% end -%>
  </div>
<% end -%>
